<% content_for :content do %>

<h3>Ustalanie praw dla ankiety <%=h   @survey.title %></h3>
<div style="padding-left: 20px;">


   <% form_tag :action => 'create_delete_rights', :id => @survey.id  do %>
			<%= hidden_field_tag :surveyID,  @survey.id %>
		
   <table cellspacing="0">
	  	<tr>
	    	<th style="width: 100px; background-color: silver;">Login</th>
			<% for right in @rights %>
				<th style="background-color: silver;"><%=h right.name %></th>
			
	    	<% end %>
		</tr>
		 
		<% for user in @users %>
		<% @name ="1"<<user.id%>
		  	<tr>
		  		
			    <td style="text-align: left;"><%=h user.login %></td>
	 		 
			    <% for right in @rights %>
			    	<% if user.access_level!=1 || right.name!="edition" %>
			    	<% 
			    		@checked=(UsersSurveysPermission.find(:first,:conditions=>"USER_ID= #{user.id} AND PERMISSION_TYPE_ID= #{right.id} AND SURVEY_ID=#{@survey.id}")!=nil)			
			    		if @checked	
			    			 @name ="[existing]"<<(user.id).to_s<<"x"<<(right.id).to_s 
			    		else
			    			 @name ="[new]"<<(user.id).to_s<<"x"<<(right.id).to_s 	
			    		end														
			    	%>
			    				<%if user.id==@author_id &&  (right.name=="edition" || right.name=="stats")%>
								<td>
									<%= hidden_field_tag  @name,  "y" %> 
									<%= check_box_tag @name, "y",true,:disabled=>true %>
                                                                </td>
								<%else%>
			    					<td> 
										<%= check_box_tag @name, "y",@checked %>
				    				</td>
				    			<% end %>		    
		
				    <% else %>
                                         <td>
						<%= check_box_tag @name, "y",false,:disabled=>true %>
					 </td>
					<% end %>		    
			
			    <% end %>
		  	</tr> 
		  	
		<% end %>
	</table>
	
	  <% for user in @temps %>
		<%  @name ="[existing]"<<(user.id).to_s<<"x"<<(@fill_id).to_s %>
			<%= hidden_field_tag  @name,  "y" %>
		 <% end %>
		
		<p><br/><%= submit_tag 'Zapisz' %>	</p>
		
		
   <% end %>
<p>
<%= link_to 'Powrót', {:id => @survey.id ,:action=>"rights_overview"} %>
</p>
</div>		

<% end %>
